//
//  UIColor+.m
//  Passwor
//
//  Created by Finalist on 8/1/13.
//  Copyright (c) 2013 sarah. All rights reserved.
//

#import "UIColor+.h"

@implementation UIColor (UIColor_)

+(UIColor *)colorWithString:(NSString *)colorString {
    if ([colorString length] != 7 || ![colorString hasPrefix:@"#"]) {
        return nil;
    }
    
    UIColor *color = nil;
    NSScanner *scanner = [[NSScanner alloc] initWithString:[colorString substringFromIndex:1]];
    unsigned hexValue;
    if ([scanner scanHexInt:&hexValue] && [scanner isAtEnd]) {
        int r = ((hexValue & 0xFF0000) >> 16);
        int g = ((hexValue & 0x00FF00) >>  8);
        int b = ( hexValue & 0x0000FF)       ;
        color = [self colorWithRed:((float)r / 255)
                             green:((float)g / 255)
                              blue:((float)b / 255)
                             alpha:1.0];
    }
    [scanner release];
    return color;
}

@end
